<template>
    <div>
        <com-heard></com-heard>
        <div class="cons">
            <div class="news pu-con">
                <div class="news-1">
                    <div class="news-12">
                        <div class="news-list">
                            <router-link
                                :to="{
                                    path: '/jsgg/dec',
                                    query: { id: item.id },
                                }"
                                v-for="(item, index) in newslist"
                                :key="index"
                            >
                                <p v-text="item.title"></p>
                                <p v-text="item.updateDate"></p>
                            </router-link>
                        </div>
                        <div class="news-page">
                            <el-pagination
                                background
                                layout="prev, pager, next"
                                :total="totalSum"
                                :page-size="sizeSum"
                                @size-change="handleSizeChange"
                                @current-change="handleCurrentChange"
                            ></el-pagination>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <com-foot></com-foot>
    </div>
</template>

<script>
import comHeard from "@/components/jsscom-heard";
import comFoot from "@/components/com-foot";
export default {
    components: {
        comHeard,
        comFoot,
    },
    data() {
        return {
            title: "",
            newslist: [],
            totalSum: 0,
            sizeSum: 30,
            prefixUrl: "",
            curIndex: 0,
        };
    },
    created() {
        this.prefixUrl = this.$store.state.user.imgUrl;
        this.curTitle = this.$route.query.title;
        this.getHyzxList(1);
    },
    mounted() {},
    methods: {
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
        },
        handleCurrentChange(val) {
            this.getIndexFigure(val);
        },
        async getHyzxList(curIndex) {
            var data = {
                title: this.curTitle,
                currentPage: curIndex,
                pageSize: this.sizeSum,
            };
            const res = await this.$store.dispatch("news/getHyzxList", data);
            console.log(res);
            this.newslist = res.list;
            this.totalSum = res.totalCount;
        },
    },
    watch: {
        $route: {
            handler: function(route) {
                this.curTitle = this.$route.query.title;
                this.getHyzxList(1);
            },
            immediate: true,
        },
    },
};
</script>

<style scoped>
@import "./news-list.css";
</style>
